import axios from 'axios';

axios.interceptors.request.use(function (config) {
    // Do something before request is sent
    return config;
  }, function (error) {
    // Do something with request error
    return Promise.reject(error);
  });

// Add a response interceptor
axios.interceptors.response.use(function (response) {
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
    return response;
  }, function (error) {
      const status = error.response.status//获取状态码 egg:401 404等等
      switch (status) {
        case "401":
                console.log("没有权限");
              break;
        case "404":
             console.log("页面找不到");
            break;
        case "304":
             console.log("临时重定向");
            break;
        case "301":
             console.log("永远重定向");
            break;
        case "500":
             console.log("服务器错误");
            break;
        default:
            console.log("您庆请求");
            break
      }
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    return Promise.reject(error);
  });

export default axios